package com.hydra.base.resp;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class Response<T> {

	public static int SC_OK = 200;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	private LocalDateTime timestamp;

	private int status;

	private T data;

	private String message;

	public Response(){
		this.timestamp = LocalDateTime.now();
	}

	public Response(int status, String message, T data){
		this();
		this.status = status;
		this.data = data;
		this.message = message;
	}

	public boolean isSuccess(){
		return this.status == SC_OK;
	}

	public static Response<?> success(Object data){
		return new Response<>(SC_OK, "请求成功", data);
	}

	public static Response<?> success(String message, Object data){
		return new Response<>(SC_OK, message, data);
	}

	public static Response<?> success(int status, String message, Object data){
		return new Response<>(status, message, data);
	}

}
